export const format = (time = '', format = 'YYYY-MM-DD HH:mm:ss', haveZero = true) => {
	let t = ''
	if (time && String(time).indexOf('-') > -1) {
		t = time.replace(/-/g, "/")
	} else {
		t = time
	}
	let date = new Date(t)
	let o = {
		'M+': date.getMonth() + 1,
		'D+': date.getDate(),
		'H+': date.getHours(),
		'm+': date.getMinutes(),
		's+': date.getSeconds(),
		'w': '日一二三四五六'.charAt(date.getDay())
	};	

	format = format.replace(/Y{4}/, date.getFullYear()).replace(/Y{2}/, date.getFullYear().toString().substring(2));

	let k, reg
	for (k in o) {
		reg = new RegExp(k);
		/* eslint no-use-before-define:0 */
		if (haveZero) {
			format = format.replace(reg, match);
		} else {
			format = format.replace(reg, o[k]);
		}
	}
	function match(m) {
		return m.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length);
	}
	return format;
}

